package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.AddressBookPageQueryResDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description AddressBookController
 * @Author dmx
 * @Date 2024-12-02
 */
@RestController("addressBookController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressBookController {


    @Autowired
    private IAddressBookService addressBookService;

    /**
     * 新增地址簿
     * @param dto
     */
    @PostMapping
    @ApiOperation("新增地址簿")
    public void addAddressBook(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.addAddressBook(dto);
    }


    /**
     * 分页查询地址簿
     * @param dto
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询地址簿")
    public AddressBookPageQueryResDTO page(AddressBookPageQueryReqDTO dto){
        return addressBookService.getPage(dto);
    }

    /**
     * 查询地址簿详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("查询地址簿详情接口")
    public AddressBookResDTO getAddressBook(@PathVariable("id") Long id){
        return addressBookService.getAddressBook(id);
    }


    /**
     * 修改地址簿
     * @param id
     * @param dto
     */
    @PutMapping("/{id}")
    @ApiOperation("修改地址簿")
    public void updateAddressBook(@PathVariable("id") Long id,@RequestBody AddressBookUpsertReqDTO dto ){
        addressBookService.updateAddressBook(id,dto);
    }


    /**
     * 设置默认地址
     * @param id
     * @param flag
     */
    @PutMapping("/default")
    @ApiOperation("设置默认地址")
    public void updateDefault(@RequestParam("id") Long id,@RequestParam("flag") Integer flag){
        addressBookService.updateDefault(id,flag);
    }


    /**
     * 地址簿的批量删除
     * @param ids
     */
//    @DeleteMapping("/batch")
//    @ApiOperation("地址簿的批量删除")
//    public void batch(@RequestBody String ids){
//        addressBookService.batch(ids);
//    }


    @DeleteMapping("/batch")
    @ApiOperation("地址簿的批量删除")
    public void batch(@RequestBody List<String> ids){
        addressBookService.batch(ids);
    }

}
